﻿Public Class Buffer
    Private Que As New Queue(Of Object)
    Private M_Size As Integer = 10

    Public Event BufferSizeChanged(ByVal NewSize As Integer)
    Public Sub Add(ByVal Value As Object)
        If Que.Count + 1 <= M_Size Then
            Que.Enqueue(Value)
            RaiseEvent BufferSizeChanged(ReturnSize)
        End If
    End Sub
    Public Sub Reset()
        Que.Clear()
        RaiseEvent BufferSizeChanged(ReturnSize)
    End Sub
    Public Function GetNext() As Object
        Return Que.Dequeue
        RaiseEvent BufferSizeChanged(ReturnSize)
    End Function
    Public Property Size() As Integer
        Get
            Return M_Size
        End Get
        Set(ByVal value As Integer)
            M_Size = value
        End Set
    End Property
    Public ReadOnly Property HaveNext() As Boolean
        Get
            If Que.Count > 0 Then
                Return True
            End If
            Return False
        End Get
    End Property
    Public ReadOnly Property Length() As Integer
        Get
            Return Que.Count
        End Get
    End Property
    Private Function ReturnSize() As Integer
        If Que.Count > 0 Then
            Return CInt((Que.Count / (M_Size / 10)) * 10)
        End If
        Return (0)
    End Function
End Class
